package com.shell.customer.chain.callback.service.impl;

import com.shell.bee.acct.transaction.po.AcctTxRec;
import com.shell.bee.base.utils.StringUtil;
import com.shell.customer.chain.callback.CallbackService;
import com.shell.customer.chain.callback.service.CustChainCallbackService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;

@Service("custChainCallbackService")
public class CustChainCallbackServiceImpl implements CustChainCallbackService {
	private Map<String, CallbackService> serviceMap = new HashMap<String, CallbackService>();

	public CustChainCallbackServiceImpl(List<CallbackService> services) {
		for (CallbackService service : services) {
			this.serviceMap.put(service.getType(), service);
		}
	}

	public void callback(AcctTxRec tx, String txSnHost) {
		CallbackService service = (CallbackService) this.serviceMap.get(tx.getTxType());
		if (StringUtil.notEmpty(txSnHost)) {
			tx.setTxSnHost(txSnHost);
			service.confirm(tx);
		} else {
			service.cancel(tx);
		}
	}
}